<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="聚焦Java性能优化 打造亿级流量秒杀系统,">










<meta name="description" content="本文为慕课网 《聚焦Java性能优化 打造亿级流量秒杀系统》视频教程的学习笔记实战视频地址： https://coding.imooc.com/class/chapter/338.html前期免费视频地址： http://www.imooc.com/learn/1079代码地址：https://gitee.com/aiolos123/secondkill 从本文开始，将进入实战课程的学习！！！">
<meta name="keywords" content="聚焦Java性能优化 打造亿级流量秒杀系统">
<meta property="og:type" content="article">
<meta property="og:title" content="【八】聚焦Java性能优化 打造亿级流量秒杀系统——实战课程简介">
<meta property="og:url" content="https://aiolos123.gitee.io/blog/2020/01/30/second-kill-system-step-by-step-8/index.html">
<meta property="og:site_name" content="Aiolos">
<meta property="og:description" content="本文为慕课网 《聚焦Java性能优化 打造亿级流量秒杀系统》视频教程的学习笔记实战视频地址： https://coding.imooc.com/class/chapter/338.html前期免费视频地址： http://www.imooc.com/learn/1079代码地址：https://gitee.com/aiolos123/secondkill 从本文开始，将进入实战课程的学习！！！">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200129153525861.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200130065124950.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200131114803470.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200129153603298.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200131120940066.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200131122342498.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200131132014837.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202135044392.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202135245899.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202135729672.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202135850540.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200131134050068.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202134830214.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20200202113325476.jpg">
<meta property="og:updated_time" content="2020-02-02T06:00:38.532Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【八】聚焦Java性能优化 打造亿级流量秒杀系统——实战课程简介">
<meta name="twitter:description" content="本文为慕课网 《聚焦Java性能优化 打造亿级流量秒杀系统》视频教程的学习笔记实战视频地址： https://coding.imooc.com/class/chapter/338.html前期免费视频地址： http://www.imooc.com/learn/1079代码地址：https://gitee.com/aiolos123/secondkill 从本文开始，将进入实战课程的学习！！！">
<meta name="twitter:image" content="https://aiolos123.gitee.io/blog/images/20200129153525861.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://aiolos123.gitee.io/blog/2020/01/30/second-kill-system-step-by-step-8/">





  <title>【八】聚焦Java性能优化 打造亿级流量秒杀系统——实战课程简介 | Aiolos</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Aiolos</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的成长点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://aiolos123.gitee.io/blog/blog/2020/01/30/second-kill-system-step-by-step-8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="aiolos">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Aiolos">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">【八】聚焦Java性能优化 打造亿级流量秒杀系统——实战课程简介</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-01-30T05:59:13+08:00">
                2020-01-30
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SpringBoot/" itemprop="url" rel="index">
                    <span itemprop="name">SpringBoot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本文为慕课网 《聚焦Java性能优化 打造亿级流量秒杀系统》视频教程的学习笔记<br>实战视频地址： <a href="https://coding.imooc.com/class/chapter/338.html" target="_blank" rel="noopener">https://coding.imooc.com/class/chapter/338.html</a><br>前期免费视频地址： <a href="http://www.imooc.com/learn/1079" target="_blank" rel="noopener">http://www.imooc.com/learn/1079</a><br>代码地址：<a href="https://gitee.com/aiolos123/secondkill" target="_blank" rel="noopener">https://gitee.com/aiolos123/secondkill</a></p>
<p>从本文开始，将进入实战课程的学习！！！</p>
<a id="more"></a>

<h2 id="免费课程中遗留问题"><a href="#免费课程中遗留问题" class="headerlink" title="免费课程中遗留问题"></a>免费课程中遗留问题</h2><blockquote>
<p>核心问题： 如何支撑亿级秒杀流量? </p>
</blockquote>
<p><img src="/blog/images/20200129153525861.jpg" alt="遗留问题"></p>
<h2 id="实战课程简介"><a href="#实战课程简介" class="headerlink" title="实战课程简介"></a>实战课程简介</h2><ol>
<li><p>课程主题： 电商秒杀系统核心高性能解决方案</p>
</li>
<li><p>电商秒杀系统的特点： 在某时间点的高并发大流量操作</p>
</li>
<li><p>本课程是基于免费秒杀项目课程做性能质的提升，该课程地址为：<a href="http://www.imooc.com/learn/1079" target="_blank" rel="noopener">http://www.imooc.com/learn/1079</a></p>
</li>
<li><p>学习互联网架构核心技术的拓展化应用；学习真正企业级的亿级秒杀优化。</p>
</li>
<li><p>本课程核心知识点<br><img src="/blog/images/20200130065124950.jpg" alt="本课程核心知识点"></p>
</li>
<li><p>开发环境</p>
<blockquote>
<p>JDK8、CentOS7.4、RocketMQ4.5.0、Apache-JMeter5.0、Redis4.0.1、phantomjs无头浏览器</p>
</blockquote>
</li>
<li><p>学习方法建议</p>
<blockquote>
<p>带着问题学习；动手动脑；深度拓展学习</p>
</blockquote>
</li>
</ol>
<h2 id="免费秒杀项目课程回顾"><a href="#免费秒杀项目课程回顾" class="headerlink" title="免费秒杀项目课程回顾"></a>免费秒杀项目课程回顾</h2><ol>
<li><p>免费秒杀项目如下图，地址为：<a href="http://www.imooc.com/learn/1079" target="_blank" rel="noopener">http://www.imooc.com/learn/1079</a><br><img src="/blog/images/20200131114803470.jpg" alt="免费秒杀项目如下图"></p>
</li>
<li><p>免费秒杀项目架构如下图<br><img src="/blog/images/20200129153603298.jpg" alt="免费秒杀项目架构如下图"></p>
</li>
<li><p>免费秒杀项目各层之间模型的交互<br>接入层————VO(视图模型)，与前端对接的模型，隐藏内部实现，供展示的聚合Model的模型<br>业务层————Domain Model(领域模型)，业务核心模型，拥有完整生命周期，贫血模型并通过Service服务来输出能力。开发中最先设计的模型。<br>数据层————DO(数据模型)，与数据库映射，用ORM方式操作数据库的能力模型</p>
</li>
</ol>
<blockquote>
<p>贫血模型(推荐)： 仅属性<br>充血模型： 属性 + Service服务</p>
</blockquote>
<p>免费秒杀项目各层之间模型的交互如下图：<br><img src="/blog/images/20200131120940066.jpg" alt="免费秒杀项目各层之间模型的交互"></p>
<ol start="4">
<li><p>数据库表的设计<br>用户表和用户密码表分离：因为密码使用频率较少，并且查询用户基本时不需要密码，减少返回数据容量<br>商品表和商品库存表分离：因为库存表是操作频繁的表，需要进行行锁或者后期可以进行分库分表优化</p>
</li>
<li><p>免费秒杀项目类图<br><img src="/blog/images/20200131122342498.jpg" alt="免费秒杀项目各层之间模型的交互"></p>
</li>
</ol>
<h2 id="免费秒杀项目课程中的问题"><a href="#免费秒杀项目课程中的问题" class="headerlink" title="免费秒杀项目课程中的问题"></a>免费秒杀项目课程中的问题</h2><ol>
<li>safri浏览器不支持跨域session共享问题</li>
</ol>
<p>解决办法： safri浏览器的阻止cookie的设置都去掉即可</p>
<ol start="2">
<li>全局异常处理无法处理404、405问题</li>
</ol>
<p>解决办法：注释掉之前的全局异常处理方法handlerException()，新创建GlobalExceptionHandler类</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 全局异常处理类，解决404、405问题</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@ControllerAdvice</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> GlobalExceptionHandler &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ExceptionHandler</span>(Exception.class) <span class="comment">//通过@ExceptionHandler注解来指定要捕获并处理的异常</span></span><br><span class="line">    <span class="meta">@ResponseBody</span></span><br><span class="line">    <span class="keyword">public</span> CommonReturnType doError(HttpServletRequest request, HttpServletResponse response,</span><br><span class="line">                                    Exception ex)&#123;</span><br><span class="line">        ex.printStackTrace();</span><br><span class="line">        Map&lt;<span class="built_in">String</span>,<span class="built_in">Object</span>&gt; respData = <span class="keyword">new</span> HashMap&lt;<span class="built_in">String</span>, <span class="built_in">Object</span>&gt;();</span><br><span class="line">        <span class="keyword">if</span>(ex <span class="keyword">instanceof</span> BusinessException)&#123;</span><br><span class="line">            <span class="comment">//过滤掉无用的异常信息</span></span><br><span class="line">            BusinessException bex = (BusinessException)ex;</span><br><span class="line">            respData.put(<span class="string">"errCode"</span>, bex.getErrCode());</span><br><span class="line">            respData.put(<span class="string">"errMsg"</span>, bex.getErrMsg());</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(ex <span class="keyword">instanceof</span> ServletRequestBindingException)&#123;</span><br><span class="line">            respData.put(<span class="string">"errCode"</span>, EmBusinessError.UNKNOWN_ERROR.getErrCode());</span><br><span class="line">            respData.put(<span class="string">"errMsg"</span>, <span class="string">"url绑定路由问题"</span>); <span class="comment">//即url必传参数未传</span></span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(ex <span class="keyword">instanceof</span> NoHandlerFoundException)&#123;</span><br><span class="line">            respData.put(<span class="string">"errCode"</span>, EmBusinessError.UNKNOWN_ERROR.getErrCode());</span><br><span class="line">            respData.put(<span class="string">"errMsg"</span>, <span class="string">"没有找到对应的访问路径"</span>);</span><br><span class="line">        &#125;<span class="keyword">else</span>  &#123;</span><br><span class="line">            respData.put(<span class="string">"errCode"</span>, EmBusinessError.UNKNOWN_ERROR.getErrCode());</span><br><span class="line">            respData.put(<span class="string">"errMsg"</span>, EmBusinessError.UNKNOWN_ERROR.getErrMsg());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> CommonReturnType.fail(respData);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>并配置全局异常</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="comment"># 配置全局异常</span></span><br><span class="line"><span class="attr">  mvc:</span></span><br><span class="line"><span class="attr">    throw-exception-if-no-handler-found:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 配置全局异常</span></span><br><span class="line"><span class="attr">  resources:</span></span><br><span class="line"><span class="attr">    add-mappings:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure>

<h2 id="服务器部署"><a href="#服务器部署" class="headerlink" title="服务器部署"></a>服务器部署</h2><blockquote>
<p>视频使用的环境为：CentOS7.6、JDK8、MySQL，本人使用服务器环境为：CentOS 6.8虚拟机、JDK8。PostgreSQL9.6为本地数据库，虚拟机通过远程访问连接到本地PostgreSQL数据库</p>
</blockquote>
<blockquote>
<p>《centos 6.8安装postgresql9.6.9实战》 <a href="https://blog.51cto.com/jxzhfei/2160711" target="_blank" rel="noopener">https://blog.51cto.com/jxzhfei/2160711</a></p>
</blockquote>
<ol>
<li>PostgreSQL允许远程访问设置方法</li>
</ol>
<p><strong>摘录自博客：<a href="https://www.cnblogs.com/telwanggs/p/10494792.html" target="_blank" rel="noopener">https://www.cnblogs.com/telwanggs/p/10494792.html</a></strong></p>
<blockquote>
<p>配置远程连接PostgreSQL数据库的步骤很简单，只需要修改data目录下的pg_hba.conf和postgresql.conf。<br>pg_hba.conf：配置对数据库的访问权限，<br>postgresql.conf：配置PostgreSQL数据库服务器的相应的参数。</p>
</blockquote>
<p>pg_hba.conf中各参数详细含义请见：<a href="https://blog.csdn.net/yaoqiancuo3276/article/details/80404883" target="_blank" rel="noopener">https://blog.csdn.net/yaoqiancuo3276/article/details/80404883</a></p>
<p>下面 介绍配置的步骤：</p>
<figure class="highlight glsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>修改pg_hba.conf文件，配置用户的访问权限（<span class="meta">#开头的行是注释内容）：</span></span><br><span class="line"></span><br><span class="line"><span class="meta"># TYPE DATABASE  USER    CIDR-ADDRESS     METHOD</span></span><br><span class="line"><span class="meta"># "local" is for Unix domain socket connections only</span></span><br><span class="line">local <span class="built_in">all</span>    <span class="built_in">all</span>               trust</span><br><span class="line"><span class="meta"># IPv4 local connections:</span></span><br><span class="line">host  <span class="built_in">all</span>    <span class="built_in">all</span>    <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>/<span class="number">32</span>     trust</span><br><span class="line">host  <span class="built_in">all</span>    <span class="built_in">all</span>    <span class="number">192.168</span><span class="number">.1</span><span class="number">.0</span>/<span class="number">32</span>    md5</span><br><span class="line"></span><br><span class="line">host  <span class="built_in">all</span>    <span class="built_in">all</span>    <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>/<span class="number">0</span>    md5</span><br><span class="line"><span class="meta"># IPv6 local connections:</span></span><br><span class="line">host  <span class="built_in">all</span>    <span class="built_in">all</span>    ::<span class="number">1</span>/<span class="number">128</span>       trust</span><br><span class="line">其中，第<span class="number">7</span>条是新添加的内容，表示允许IP为<span class="number">192.168</span><span class="number">.1</span><span class="number">.0</span>上的所有合法的数据库用户名访问数据库，并提供加密的密码验证。</span><br><span class="line">其中，第<span class="number">8</span>条是新添加的内容，表示允许所有主机使用所有合法的数据库用户名访问数据库，并提供加密的密码验证。</span><br><span class="line"></span><br><span class="line">/<span class="number">32</span>表示IPv4; /<span class="number">128</span>表示IPv6；</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span>修改postgresql.conf文件，将数据库服务器的监听模式修改为监听所有主机发出的连接请求。</span><br><span class="line"></span><br><span class="line">定位到<span class="meta">#listen_addresses=’localhost’。PostgreSQL安装完成后，默认是只接受来在本机localhost的连接请 求。</span></span><br><span class="line"></span><br><span class="line">将行开头都<span class="meta">#去掉，将行内容修改为listen_addresses=’*'来允许数据库服务器监听来自任何主机的连接请求</span></span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 修改完重启PGSQL服务</span><br></pre></td></tr></table></figure>

<p>本地数据库的修改如下图：<br><img src="/blog/images/20200131132014837.jpg" alt="PostgreSQL允许远程访问设置方法"></p>
<ol start="2">
<li><p>maven打包上传</p>
<blockquote>
<p>maven install</p>
</blockquote>
</li>
<li><p>外挂配置文件application.yml, 其中修改了启动端口</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="symbol">server:</span></span><br><span class="line"><span class="symbol">  port:</span> <span class="number">80</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<p>外挂配置文件application.yml的命令如下：</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">java -jar second-kill-<span class="number">1.0</span>-SNAPSHOT<span class="selector-class">.jar</span> --spring<span class="selector-class">.config</span><span class="selector-class">.addition-location</span>=/home/application.yml</span><br></pre></td></tr></table></figure>

<p>即可使用application.yml中的配置启动项目。<br><img src="/blog/images/20200202135044392.jpg" alt="外挂配置文件application.yml"></p>
<p>此时，即可通过浏览器访问到服务器上的项目(注意：需要关闭服务器的防火墙或允许80端口)<br><img src="/blog/images/20200202135245899.jpg" alt="访问到服务器上的项目"></p>
<ol start="4">
<li><p>编写deploy.sh启动脚本</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 最大最小堆栈 400m; 新生代大小：200m</span></span><br><span class="line">nohup java -Xms400m -Xmx400m -XX:<span class="attribute">NewSize</span>=200m -XX:<span class="attribute">MaxNewSize</span>=200m -jar second-kill-1.0-SNAPSHOT.jar --spring.config.<span class="attribute">addition-location</span>=/home/application.yml</span><br></pre></td></tr></table></figure>
</li>
<li><p>授权启动脚本</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">chmod</span> 777 <span class="selector-tag">deploy</span><span class="selector-class">.sh</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>启动，日志输出到nohup.out中</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./deploy<span class="selector-class">.sh</span> &amp;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<p>即可使用启动脚本启动项目。<br><img src="/blog/images/20200202135729672.jpg" alt="使用启动脚本启动项目"></p>
<p>此时，即可通过浏览器访问到服务器上的项目(注意：需要关闭服务器的防火墙或允许80端口)<br><img src="/blog/images/20200202135850540.jpg" alt="访问到服务器上的项目"></p>
<h2 id="jar运行报错-no-main-manifest-attribute"><a href="#jar运行报错-no-main-manifest-attribute" class="headerlink" title="jar运行报错:no main manifest attribute"></a>jar运行报错:no main manifest attribute</h2><ol>
<li><p>springboot项目打包成jar后，运行jar会出现下面错误<br><img src="/blog/images/20200131134050068.jpg" alt="运行jar会出现下面错误"></p>
</li>
<li><p>解决办法：springboot项目在pom.xml里面添加如下配置</p>
<blockquote>
<p>注意： build标签下一定要去掉pluginManagement标签，否则即使配置了下面的代码，也无法正确生成jar包，还是会报上述错误</p>
</blockquote>
</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>添加配置如下：<br><img src="/blog/images/20200202134830214.jpg" alt="添加配置"></p>
<p>添加上述配置前后生成的jar包如下：<br><img src="/blog/images/20200202113325476.jpg" alt="修复jar报错"></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/聚焦Java性能优化-打造亿级流量秒杀系统/" rel="tag"># 聚焦Java性能优化 打造亿级流量秒杀系统</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2020/01/29/second-kill-system-step-by-step-7/" rel="next" title="【七】聚焦Java性能优化 打造亿级流量秒杀系统——电商秒杀项目课程总结">
                <i class="fa fa-chevron-left"></i> 【七】聚焦Java性能优化 打造亿级流量秒杀系统——电商秒杀项目课程总结
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2020/01/31/second-kill-system-step-by-step-9/" rel="prev" title="【九】聚焦Java性能优化 打造亿级流量秒杀系统——性能压测">
                【九】聚焦Java性能优化 打造亿级流量秒杀系统——性能压测 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">aiolos</p>
              <p class="site-description motion-element" itemprop="description">Java Spring Hadoop 机器学习</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">126</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#免费课程中遗留问题"><span class="nav-number">1.</span> <span class="nav-text">免费课程中遗留问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实战课程简介"><span class="nav-number">2.</span> <span class="nav-text">实战课程简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#免费秒杀项目课程回顾"><span class="nav-number">3.</span> <span class="nav-text">免费秒杀项目课程回顾</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#免费秒杀项目课程中的问题"><span class="nav-number">4.</span> <span class="nav-text">免费秒杀项目课程中的问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#服务器部署"><span class="nav-number">5.</span> <span class="nav-text">服务器部署</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jar运行报错-no-main-manifest-attribute"><span class="nav-number">6.</span> <span class="nav-text">jar运行报错:no main manifest attribute</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">aiolos</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
